﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using Model;
using HT.DBUtility;

namespace HT.DAL
{
    public class Dal_TempStorage_1
    {
        public Dal_TempStorage_1()
        { }


        /// <summary>
        /// 从 条件表中获取信息
        /// </summary>
        /// <param name="content">查询内容</param>
        /// <param name="tableName">表名</param>
        /// <param name="condition">条件(含 where 部分)</param>
        /// <returns></returns>
        public string GetDataByFiled(string content, string tableName, string condition)
        {
            StringBuilder strSql = new StringBuilder();
            string name = "";
            strSql.Append("select " + content + "  from  " + tableName + condition);
          //  DataTable dt = SQLHelper.ExecuteDt(strSql.ToString());

            object obj = SQLHelper.GetSingle(strSql.ToString());

            if (obj != null)
            {
                name = obj.ToString();
            }
    
            return name;
        }


 

        /// <summary>
        /// 删除 h
        /// </summary>
        /// <returns></returns>
        public int DeleteTempStorageH(string djlsh)
        {
            string sql = "delete TempStorageH where tempdjh='" + djlsh + "'";
            int ss = SQLHelper.ExecuteSql(sql);
            return ss;
        }

        

        /// <summary>
        /// 删除 b
        /// </summary>
        /// <returns></returns>
        public int DeleteTempStorageB(string djlsh)
        {
            string sql = "delete TempStorageB where tempdjh='" + djlsh + "'";
            int ss = SQLHelper.ExecuteSql(sql);
            return ss;
        }


        /// <summary>
        /// 暂存
        /// </summary>
        /// <param name="sqlList"></param>
        /// <returns></returns>
        public int SaveXskdData(List<string> sqlList)
        {
            int s1 = SQLHelper.ExecuteSqlTran(sqlList);
            return s1;
        }

        /// <summary>
        /// 获取暂存单(tempstorage)List
        /// </summary>
        /// <param name="djlsh"></param>
        /// <returns></returns>
        public DataTable GetTempStorageData(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select tempDjh,Khbh,Khmc,Yyybh,Yyymc,Sl,Je,temptime from  dbo.TempStorageH ");
            if (strWhere != "")
            {
                strSql.Append(" where " + strWhere + " order by tempDjh desc");
            }
            else
            {
                strSql.Append(" order by tempDjh desc");
            }

            DataTable dt = SQLHelper.ExecuteDt(strSql.ToString());
 

            return dt;
        }

        /// <summary>
        /// 获取暂存单(tempstorage)List
        /// </summary>
        /// <param name="djlsh"></param>
        /// <returns></returns>
        public DataTable GetTempStorageBData(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select tempDjlsh,hh,spbh,tmh,spmc,gg,dw,sl,dj,ssje,zke,zkl,yyymc,bdz,cj,cjhh,jj,gysmc,pfj,zhj FROM TempStorageb ");
            if (strWhere != "")
            {
                strSql.Append(" where " + strWhere + " order by tempDjlsh desc");
            }
            else
            {
                strSql.Append(" order by tempDjlsh desc");
            }

            DataTable dt = SQLHelper.ExecuteDt(strSql.ToString());
            return dt;
        }




        #region 保存暂存单据

        /// <summary>
        /// 添加暂存数据 h
        /// </summary>
        /// <returns></returns>
        public string GetTempStorageHStr(TempStorageH model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TempStorageH(");
            strSql.Append("tempDjh,Khbh,Khmc,Yyybh,Yyymc,Sl,Je,temptime)");
            strSql.Append(" values (");
            strSql.Append(model.tempDjh + ",'" + model.Khbh + "','" + model.Khmc + "','" + model.Yyybh + "','" + model.Yyymc + "'," + model.Sl + "," + model.Je + ",'" + model.TempTime + "')");
            return strSql.ToString();
        }

        /// <summary>
        /// 获取插入字符串
        /// </summary>
        /// <returns></returns>
        public string GetTempStorageStringBuilder(TempStorageB model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into TempStorageB(");
            strSql.Append("tempDjlsh,hh,spbh,tmh,spmc,gg,dw,sl,dj,ssje,zke,zkl,yyymc,bdz,cj,cjhh,jj,gysmc,pfj,zhj)");
            strSql.Append(" values (");
            strSql.Append(+model.tempDjlsh + "," + model.hh + ",'" + model.spbh + "','"+model.tmh+"', '" + model.spmc + "',");
            strSql.Append("  '" + model.gg + "','" + model.dw + "'," + model.sl + "," + model.dj + ",");
            strSql.Append(model.ssje + "," + model.zke + "," + model.zkl + ",");
            strSql.Append("'" + model.yyymc + "'," + model.bdz + ",'" + model.cj + "','" + model.cjhh + "'," + model.jj + ",'" + model.gysmc + "'," + model.pfj + "," + model.zhj + ")");
            return strSql.ToString();
        }

        public int ExecuteSqlTranBuilder(List<string> sqlList)
        {
            int ss = SQLHelper.ExecuteSqlTran(sqlList);
            return ss;
        }

        #endregion



    }
}
